package sg.edu.nus.iss.cats.javabean;

import sg.edu.nus.iss.cats.model.*;
import sg.edu.nus.iss.cats.controller.*;
import sg.edu.nus.iss.cats.dataaccess.DAOException;


public class DepartmentsBean{

    public String getUserManagerMenu(Department department){
    
        User[] managers = null;
        try{
            UserManager userManager = new UserManager();
            managers = userManager.findAllManagers();      

        }catch(DAOException e){
        
            System.out.println("Sorry, the managers info could not be found");
        }
        //Loop around all managers and display the pull down menu list for user 
        String menu = null;
        
         System.out.println("Manager: " + department.getManagerInCharge());
        for (int j=0;j<managers.length;j++){

            if (department.getManagerInCharge().equals(managers[j].getUserId())){
                menu += "<option value=\"" + managers[j].getUserId() +"\""; 
                menu += " selected>" + managers[j].getName() + "</option>\n";

            } else {                    
               menu += "<option value=\"" + managers[j].getUserId() +"\""; 
               menu += ">" + managers[j].getName() + "</option>\n";
             }

        }
        
        return menu;
    }
    
    
    public String getAllManagerMenu(){
        
        User[] managers = null;
        try{
            UserManager userManager = new UserManager();
            managers = userManager.findAllManagers();      

        }catch(DAOException e){

            System.out.println("Sorry, the managers info could not be found");
        }
        //Loop around all managers and display the pull down menu list for user 
        String menu = null;
        for (int j=0;j<managers.length;j++){                               
               menu += "<option value=\"" + managers[j].getUserId() +"\""; 
               menu += ">" + managers[j].getName() + "</option>\n";

        }

        return menu;
    }
    
}